/**
 * Copyright (c) 2017, Alex. All rights reserved.
 */
package com.oschina.bottle.sample.web.web.exception;

import com.oschina.bottle.common.model.Result;
import com.oshina.bottle.utils.http.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一异常处理
 *
 * @author <a href="mailto:zhongchao@gegejia.com">zhong</a>
 * @version 1.0 2017/10/11
 * @since 1.0
 */
@ControllerAdvice
@ResponseBody
public class CommonExceptionHandler
{
    private final static Logger logger = LoggerFactory.getLogger(CommonExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public Object HandleException(HttpServletRequest request, Exception ex) {
        logger.error("请求：{}，参数: {}, 参数异常: ", request.getRequestURI(), HttpUtils.getParam(request), ex);
        return Result.fail(ex);
    }

}
